package com.eascs.finance.admin.web.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.eascs.common.util.StringUtil;
import com.eascs.finance.admin.server.manager.impl.BaseDao;
import com.eascs.site.tag.select.SelectDataService;

@Service
public class SelectDataServiceImpl extends BaseDao implements SelectDataService {

	
	public List<Object[]> getDataSouce(String dataSouceType, String dataSouceFrom) {

		List<Object[]> dataSouceList = new ArrayList<>();
		List<Object> listParams = new ArrayList<Object>();
		StringBuffer sql = new StringBuffer();
	
		if (StringUtil.isNotBlank(dataSouceType)) {

			if (dataSouceType.equals("ArtileItem")) {
				sql.append(" select id,item_name from  article_item where is_lock=0 and status=2");
				dataSouceList = this.findObjectsList(sql.toString());
			} else {
				sql.append("SELECT item.item_code,item.item_name FROM datadic_item item");
				sql.append(" where item.dd_no = (select dic.id  from 	datadic dic  where 1=1");
				sql.append(" and dd_code= ? )");
				listParams.add(dataSouceType);
				if (StringUtil.isNotBlank(dataSouceFrom)) {
					sql.append(" and parent_code= ?");
					listParams.add(dataSouceFrom);
				}
				sql.append(" order by  item_code  asc ");
				dataSouceList = this.findObjectsList(sql.toString(), listParams.toArray());
			}

		}
		

		return dataSouceList;
	}

}
